home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / networking / HIPPI / sink.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  2.3 KB  |  93 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * sink.c
  19.  *
  20.  * sink [-1] [-D<device-file>] [size]
  21.  *
  22.  * Test HIPPI-FP interface input performance.
  23.  *
  24.  */
  25. #include <stdio.h>
  26. #include <fcntl.h>
  27. #include <stdlib.h>
  28. #include <sys/types.h>
  29. #include <sys/wait.h>
  30. #include <sys/times.h>
  31.  
  32. #include <sys/hippi.h>
  33.  
  34. #define DEVICE_FILE    "/dev/hippi0"
  35.  
  36. main(int argc, char *argv[] )
  37. {
  38.     int    i, n, fd, status;
  39.     int    len=0x200000, nofork = 0, retv;
  40.     int    child, arg;
  41.     u_long    *buf, *buf1,*buf2;
  42.     char    *device_name = DEVICE_FILE;
  43.  
  44.     arg = 1;
  45.     if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == '1' )
  46.         nofork++,arg++;
  47.     if ( argc>arg && argv[arg][0] == '-' && argv[arg][1] == 'D' )
  48.         device_name = argv[arg++]+2;
  49.     if ( argc>arg )
  50.         len = atoi( argv[arg++] );
  51.     
  52.     if ( len < 4 )
  53.         fprintf(stderr,"Bad length argument: %d\n", len ),exit(1);
  54.     
  55.     buf1 = memalign( 8, len );
  56.     buf2 = memalign( 8, len );
  57.     printf("%s : receiving into %d size buffers\n", device_name, len );
  58.  
  59.     mpin( buf1, len );
  60.     mpin( buf2, len );
  61.  
  62.     fd = open( device_name, O_RDONLY );
  63.     if ( fd < 0 )
  64.         perror( "couldn't open hippi device" ),exit(1);
  65.     
  66.     /* Set ULP */
  67.     if ( ioctl( fd, HIPIOC_BIND_ULP, 0x17 ) < 0 )
  68.         perror( "couldn't bind to ULP" ),exit(1);
  69.     
  70.     if ( ! nofork )
  71.         child = ( fork() == 0 );
  72.     else
  73.         child = 0;
  74.  
  75.     buf =  child ? buf1 : buf2;
  76.  
  77.     n=0;
  78.     for (;;) {
  79.         retv = read( fd, buf, len );
  80.         if ( retv < 0 ) {
  81.             printf("(%s) : read return value: %d\n",
  82.                 child ? "child" : "parent", retv );
  83.             perror( "trouble reading" );
  84.             exit(1);
  85.         }
  86.         n++;
  87.         if ( ! child && (n&127) == 0 )
  88.             printf( "%d packets received by parent\n", n );
  89.         else if ( child && (n&127) == 64 )
  90.             printf( "%d packets received by child\n", n );
  91.     }
  92. }
  93.